package test;
//生成序列化文件Demo
import java.io.IOException;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.*;
public class SequenceFileWriteDemo {
    private static String[] myValue = {
	    "hello world",
		"bye world",
		"hello hadoop",
		"bye hadoop"
	};
	public static void main(String[] args) throws IOException {
	    String uri = "hdfs://localhost:9000/user/tuxinhui/output1/";
		Configuration conf = new Configuration ();
		FileSystem fs = FileSystem.get(URI.create(uri), conf);
		Path path = new Path(uri);
		IntWritable key = new IntWritable ();
		Text value = new Text();
		SequenceFile.Writer writer = null;
		try {
		    writer = SequenceFile.createWriter (fs, conf, path, key.getClass(), value.getClass() );
			for (int i = 0; i < 5000; i++){
			    key.set(5000000 - i);
				value.set (myValue[i % myValue.length]);
				writer.append (key, value);
			}
		} finally {
		    IOUtils.closeStream (writer);
		}
	}
}
